<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>美兰数据文化馆与图书馆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="authtree-submit-form">
                <input type="hidden" name="tid">
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基础信息</li>
                        <li>权限信息</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">角色名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="rolename" lay-verify="rolename"
                                                   autocomplete="off" placeholder="请输入角色名称"
                                                   class="layui-input" id="rolename" disabled>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">角色代码</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="rolecode" lay-verify="rolecode"
                                                   autocomplete="off"
                                                   class="layui-input" disabled>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">已授权用户</label>
                                        <div class="layui-input-block" id="checkbox">

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">角色描述</label>
                                        <div class="layui-input-block">
                                                <textarea type="text" name="remark"
                                                          autocomplete="off"
                                                          class="layui-textarea"></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-row">
                                <div class="layui-col-md3">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-input-block">
                                            <div id="LAY-auth-tree-index0"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-input-block">
                                            <div id="LAY-auth-tree-index1"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-input-block">
                                            <div id="LAY-auth-tree-index2"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-input-block">
                                            <div id="LAY-auth-tree-index3"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    function child(tid) {
        layui.use(['form', 'laydate','authtree'], function () {
            var $ = layui.$
                , form = layui.form
                , laydate = layui.laydate
                , layer = layui.layer,
                authtree=layui.authtree;

            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/system/getRoleByTid",
                dataType: "json",
                data: "tid=" + tid,
                async: false,
                success: function (data) {
                    form.val("authtree-submit-form", data)
                }
            })

            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/system/getAuthorizeByRoleTid",
                dataType: "json",
                data: "tid=" + tid,
                async: false,
                success: function (msg) {
                    if(msg.count!=0){
                        for (var j = 0; j < msg.data.length; j++) {
                            var radio = '<input type="checkbox" checked="true"  value="' + msg.data[j].tid + '" title="' + msg.data[j].name + '"/>';
                            $("#checkbox").append(radio);
                        }
                        form.render("checkbox");
                    }
                }
            })

            $.ajax({
                type: "post",
                url: '<%=request.getContextPath()%>/rest/system/getMenuRoleListByRole',
                dataType: "json",
                async: false,
                data:"tid="+tid,
                success: function (res) {
                    if (res != null) {
                        for (var i = 0; i < res.length; i++) {
                            authtree.render('#LAY-auth-tree-index' + i, res[i].data.trees, {
                                inputname: 'permission' + i
                                // , layfilter: 'lay-check-auth'
                                , openall: true
                                , theme: 'auth-skin-default'
                                , themePath: '<%=request.getContextPath()%>/huazhi/js/lay-module/authtree/'
                                , autowidth: true
                                , formFilter: 'authtree-submit-form' // 注意！！！如果不与其他插件render冲突，这个选填
                            });
                        }
                    }

                }
            })


        });
    }
</script>
</body>
</html>